import { defineStore } from 'pinia'
import { computed, ref } from 'vue'

export const useAdminStore = defineStore('admin', () => {
  // 状态
  const adminList = ref([])
  const loading = ref(false)
  const error = ref(null)

  // getters
  const getAdminList = computed(() => adminList.value)
  const isLoading = computed(() => loading.value)

  // actions
  const fetchAdminData = async () => {
    loading.value = true
    try {
      // 这里应该调用实际的API
      // const data = await getAdminData()
      const data = []
      adminList.value = data
      error.value = null
    } catch (err) {
      error.value = err.message || '获取管理数据失败'
      console.error('获取管理数据失败:', err)
    } finally {
      loading.value = false
    }
  }

  return {
    adminList,
    loading,
    error,
    getAdminList,
    isLoading,
    fetchAdminData
  }
})
